package com.xt.yncu.login.service;

import java.util.Map;

import com.xt.base.dao.hibernate.BaseDaoHibernate;
import com.xt.base.model.base.Organization;
import com.xt.base.model.base.SpelledField;
import com.xt.base.model.system.User;
import com.xt.base.service.BaseService;
import com.xt.base.wireless.server.MobileActionUtil;
import com.xt.yncu.common.util.XmlParse;
import com.xt.yncu.login.dao.LoginMobileDao;
import com.xt.yncu.soap.SOAPInterface;

/**
 *  <br>
 * <br>
 * 
 * <p>
 * <a href=".java.html"><i>查看源文件</i></a>
 * </p>
 * 
 * @author 杨洪波
 * @create-date:2011-11-3
 */
public class LoginMobileService extends BaseService{
	private static final long serialVersionUID = 851264688430750269L;
	private SOAPInterface soapInterface;
	private LoginMobileDao loginMobileDAO;

	public String login(Map<String,Object> destMap){
		//Map<String,Object> destMap = MobileActionUtil.parseRequestXml(xml);
		String simNum = String.valueOf(destMap.get("simNum"));
		destMap.remove("simNum");
		String logXml=soapInterface.send(destMap);
		/*if (XmlParse.isXml(logXml)) {
			Map<String, Object> map=MobileActionUtil.parseRequestXml(logXml);
			if (!XmlParse.isException(logXml)) {
				if ("true".equals(map.get("success"))) {
					Organization organization = this.loginMobileDAO.getOrgByOrgid(
							String.valueOf(map.get("orgid")));
					if (organization == null) {
						SpelledField spelledField = new SpelledField(String
								.valueOf(map.get("orgzhname")));
						organization = new Organization();
						organization.setName(spelledField);
						organization.setCode(String.valueOf(map.get("orgid")));
						loginMobileDAO.save(organization);
					}
					
					User user = this.loginMobileDAO.getUserByUserid(
							String.valueOf(map.get("userid")));
					if (user == null) {
						user = new User();
						user.setCode(String.valueOf(map.get("userid")));
						user.setUsername(String.valueOf(map.get("username")));
						user.setPassword(String.valueOf(map.get("password")));
						user.setZhname(new SpelledField(String.valueOf(map
								.get("userzhname"))));
						user.setSimNum(simNum);
						user.setOrg(organization);
						loginMobileDAO.save(user);
					}
				}
			}
		}*/
		return logXml;
	}

	public void setSoapInterface(SOAPInterface soapInterface) {
		this.soapInterface = soapInterface;
	}
	
	@Override
	public BaseDaoHibernate getDao() {
		return loginMobileDAO;
	}

	public void setLoginMobileDAO(LoginMobileDao loginMobileDAO) {
		this.loginMobileDAO = loginMobileDAO;
	}

}
